# 后台用户模型
class User < ActiveRecord::Base
  validates :name, presence: { message: '用户名不能为空'}
  validates :name, uniqueness: { message: '用户名已存在'}
  validates :password, presence: { message: '密码不能为空' }, on: :create
  validates :password, length: { minimum: 6, message: '密码不能小于6位'}, unless: Proc.new {|user| user.password.blank?}
  validates :password_confirmation, presence: { message: '确认密码不能为空'}, on: :create
  validates :password, confirmation: { message: '两次输入密码不一致' }, unless: Proc.new {|user| user.password.blank?}
  has_secure_password
end
